//
//  HMEmoticonButton.swift
//  WeiBo14
//
//  Created by HM on 16/3/14.
//  Copyright © 2016年 HM. All rights reserved.
//

import UIKit

class HMEmoticonButton: UIButton {

    // 当前按钮显示的表情数据
    var emoticon: HMEmoticon? {
        didSet{
            // 2. 显示数据
            if emoticon!.type == "0" {
                let image = UIImage(named: "\(emoticon!.folderName!)/\(emoticon!.png!)", inBundle: HMEmoticonTools.sharedTools.emoticonsBundle, compatibleWithTraitCollection: nil)
                self.setImage(image, forState: UIControlState.Normal)
                // 清空掉title,以防止重用出现的问题
                self.setTitle(nil, forState: UIControlState.Normal)
            }else{
                let title = (emoticon!.code! as NSString).emoji()
                self.setTitle(title, forState: UIControlState.Normal)
                self.setImage(nil, forState: UIControlState.Normal)
            }
        }
    }

}
